package com.zhao.modleclass.activity;

import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.util.TypedValue;
import android.view.Window;
import android.widget.MediaController;
import android.widget.VideoView;

import com.zhao.modleclass.R;

import butterknife.Bind;
import butterknife.ButterKnife;

public class PlayVideoActivity extends AppCompatActivity {

    @Bind(R.id.vv_PlayVideo)
    VideoView vvPlayVideo;

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_playvideo);
        //设置状态栏的颜色
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            //获取样式中的属性值
            TypedValue typedValue = new TypedValue();
            this.getTheme().resolveAttribute(Color.parseColor("#FF4081"), typedValue, true);
            int[] attribute = new int[]{Color.parseColor("#FF4081")};
            TypedArray array = this.obtainStyledAttributes(typedValue.resourceId, attribute);
            int color = array.getColor(0, Color.parseColor("#FF4081"));
            array.recycle();
            window.setStatusBarColor(color);
        }
        ButterKnife.bind(this);
        Intent intent=getIntent();
        String urlvideo = intent.getStringExtra("urlvideo");
        //给video view设置控制器
        vvPlayVideo.setMediaController(new MediaController(this));
        vvPlayVideo.setVideoURI(Uri.parse(urlvideo));
        //让videoview获得焦点
        vvPlayVideo.requestFocus();
        //加载视频

        //开始播放
        vvPlayVideo.start();
    }
}
